<?php
class auto extends ujn_controller {

	var $auto_render = false;

	private $act_path;
	function _before() {
		$this->act_path = dirname(__FILE__) . '/act/';
		include_once $this->act_path . 'func.php';
	}
	
	public function save_friends() {
		$aRet = mdl_other_friends::getInstance()->getRows();
		if(empty($aRet) || !is_array($aRet)) return false;

		$mids = $sitemids = $aF = array();
		foreach($aRet as $r) {
			$mids[] = $r['mid'];
			$r['friends_str'] = json_decode($r['friends_str'], true);
			foreach( (array)$r['friends_str'] as $f ) {
				$sitemids[] = $f['uid'];
				$aF[$f['uid']] = sexConvert($f['sex']);
			}
		}
		
		$aSearch = mdl_member_vote::getInstance()->search($sitemids);
		foreach($aSearch as $s) {
			if(isset($aF[$s['sitemid']])) unset($aF[$s['sitemid']]);
		}
		
		if(mdl_member_vote::getInstance()->saveUser($aF)) {
			mdl_other_friends::getInstance()->deleteRows($mids);
		}
	}
}